package src.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import src.hospital.Usuario;

public class HibernateUsuarioDAO implements InterfaceDAO <Usuario, Long> {

	

		  private SessionFactory sessionFactory = null;

		  public void setSessionFactory(SessionFactory sessionFactory) {
		    this.sessionFactory = sessionFactory;
		  }

		  public HibernateUsuarioDAO() {}

		  public HibernateUsuarioDAO (SessionFactory sessionFactory) {
		    setSessionFactory(sessionFactory);
		  }

		
	public Usuario save(Usuario entity) {
		Session session = sessionFactory.getCurrentSession();
	    session.saveOrUpdate(entity);
	    return entity;
	}

	public void delete(Usuario entity) {
		sessionFactory.getCurrentSession().delete(entity);
		
	}

	public Usuario findByPrimaryKey(Long id) {
		Session session = sessionFactory.getCurrentSession();
	    Object o = session.load(Usuario.class, id);
	    return (Usuario)o;
	}

	public List<Usuario> findAll() {
		Session session = sessionFactory.getCurrentSession();
	    Query queryResult = session.createQuery("from usuario");
	    return queryResult.list();
	}
}
